# Contributor: Isaac Dunham <ibid.ag@gmail.com>
# Maintainer: Dominika Liberda <ja@sdomi.pl>
pkgname=xpdf
pkgver=4.05
pkgrel=0
pkgdesc="The classic X11 PDF viewer"
url="https://www.xpdfreader.com/"
arch="all"
license="GPL-2.0-or-later OR GPL-3.0-or-later"
options="!check" # no tests
depends="ghostscript-fonts"
makedepends="cmake qt5-qtbase-dev samurai"
subpackages="$pkgname-doc"
source="https://dl.xpdfreader.com/xpdf-$pkgver.tar.gz
	permissions.patch"

# secfixes:
#   4.05-r0:
#     - CVE-2022-30524
#     - CVE-2022-30775
#     - CVE-2022-33108
#     - CVE-2022-36561
#     - CVE-2022-38222
#     - CVE-2022-38334
#     - CVE-2022-38928
#     - CVE-2022-41842
#     - CVE-2022-41843
#     - CVE-2022-41844
#     - CVE-2022-43071
#     - CVE-2022-43295
#     - CVE-2022-45586
#     - CVE-2022-45587
#     - CVE-2022-48545
#     - CVE-2023-2662
#     - CVE-2023-2663
#     - CVE-2023-2664
#     - CVE-2023-26930
#     - CVE-2023-3044
#     - CVE-2023-3436
#   4.04-r0:
#     - CVE-2022-24106
#     - CVE-2022-24107
#     - CVE-2022-38171
#   4.03-r0:
#     - CVE-2020-25725
#     - CVE-2020-35376

build() {
	if [ "$CBUILD" != "$CHOST" ]; then
		CMAKE_CROSSOPTS="-DCMAKE_SYSTEM_NAME=Linux -DCMAKE_HOST_SYSTEM_NAME=Linux"
	fi
	cmake -B build -G Ninja \
		-DCMAKE_INSTALL_PREFIX=/usr \
		-DCMAKE_INSTALL_LIBDIR=lib \
		-DBUILD_SHARED_LIBS=True \
		-DCMAKE_BUILD_TYPE=MinSizeRel \
		-DSYSTEM_XPDFRC=/etc/xpdfrc \
		$CMAKE_CROSSOPTS
	cmake --build build
}

package() {
	DESTDIR="$pkgdir" cmake --install build

	# delete pdf* utils and associated man pages that conflict with
	# poppler-utils.
	rm -f "$pkgdir"/usr/bin/pdf*
	rm -f "$pkgdir"/usr/share/man/man1/pdf*

	# install xpdfrc
	install -Dm644 doc/sample-xpdfrc "$pkgdir"/etc/xpdfrc
}

sha512sums="
1ee18a2fcae138e60158cf6289f588832a982e1b13995382a396d1953949cf4e32cb4f9884f2506154512d961853e70ff499a35c525e707c3bf2950fe7f9040b  xpdf-4.05.tar.gz
cf56bf9b4ccecc85fd34805454513b921bfe044442dad129178cde6f9ff2fae322bf0d71aaa69b9456aa0f41d639bc3a6aa2c7dcaae177013ac45e92f9fc3125  permissions.patch
"
